//
//  UniteModel.m
//  MFElectromobile
//
//  Created by lin'quan on 16/10/19.
//  Copyright © 2016年 linquan. All rights reserved.
//

#import "UniteModel.h"
//#import "NSString+Encoded.h"

@implementation UniteModel

+ (NSArray *)getRentDates
{
    
    //    return @[@"今天",@"明天",[self getLaterDateWithDays:2],[self getLaterDateWithDays:3],[self getLaterDateWithDays:4],[self getLaterDateWithDays:5],[self getLaterDateWithDays:6]];

    
    
    NSDate *dates = [NSDate date];
    NSTimeInterval interval = 0;//延时
    NSDate *detea = [NSDate dateWithTimeInterval:interval sinceDate:dates];
    NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"BeiJing"];
    [formatter setTimeZone:timeZone];
    
    
    [formatter setDateFormat:@"HH"];
    //    NSDate *date = [NSDate date];
    NSString *curDate = [NSString stringWithFormat:@"%@",[formatter stringFromDate:detea]];
    int nowHours = [curDate intValue];
    NSInteger maxPretime = [[NSUserDefaults standardUserDefaults] integerForKey:@"max_pretime"];
    int appointmentEnd = 24;
    if (maxPretime) {
        appointmentEnd = (int)maxPretime;
    }
    
    if ((23-nowHours)>=appointmentEnd) {
        return @[@"今天"];
    }else if ((23-nowHours)<appointmentEnd&&(23-nowHours)+24>=appointmentEnd){
        return @[@"今天",@"明天"];
    }else{
        NSMutableArray *tempAaary = [NSMutableArray array];
        int dataCount = (appointmentEnd - (23-nowHours))/24 + 2;
        if (dataCount > 2) {
            for (int i=0; i<dataCount; i++) {
                if (i==0) {
                    [tempAaary addObject:@"今天"];
                }else if (i==1){
                 [tempAaary addObject:@"明天"];
                }else{
                    [tempAaary addObject:[self getLaterDateWithDays:i+2]];
                }
            }
        }
        return tempAaary.copy;
    }
    return @[@"今天",@"明天"];
}


+ (NSArray *)getRentHours
{
    
    
    NSArray *hoursArray = @[@"00",@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23"];
    
    
    
    return hoursArray;
}
//返回今天的可预约小时
+ (NSArray *)getTodayRentHours
{
    int appointmentStar = 2;
    NSInteger minPretime = [[NSUserDefaults standardUserDefaults] integerForKey:@"min_pretime"];
    if (minPretime) {
        appointmentStar = (int)minPretime;
    }
    
    NSArray *hoursArray = @[@"00",@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23"];
    NSDate *dates = [NSDate date];
    NSTimeInterval interval = 60 * 60 * appointmentStar + 120;//起始时间
    
    NSDate *detea = [NSDate dateWithTimeInterval:interval sinceDate:dates];
    NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"BeiJing"];
    [formatter setTimeZone:timeZone];
    
 
    [formatter setDateFormat:@"HH"];
//    NSDate *date = [NSDate date];
    NSString *curDate = [NSString stringWithFormat:@"%@",[formatter stringFromDate:detea]];
    NSUInteger nowHours = [curDate integerValue];
    
    NSMutableArray *hours = [NSMutableArray array];
    for (long i = nowHours; i<= 23; i++) {
        [hours addObject:hoursArray[i]];
    }
    return hours.copy;
    
}
//返回最后一天的可预约小时
+ (NSArray *)getLastDayRentHours
{
    int appointmentEnd = 24;
    NSInteger maxPretime = [[NSUserDefaults standardUserDefaults] integerForKey:@"max_pretime"];
    if (maxPretime) {
        appointmentEnd = (int)maxPretime;
    }
//    int appointmentEnd = 34;
    NSArray *hoursArray = @[@"00",@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23"];
    NSDate *dates = [NSDate date];
    NSTimeInterval interval = 0;//起始时间
    
    NSDate *detea = [NSDate dateWithTimeInterval:interval sinceDate:dates];
    NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"BeiJing"];
    [formatter setTimeZone:timeZone];
    
    
    [formatter setDateFormat:@"HH"];
    //    NSDate *date = [NSDate date];
    NSString *curDate = [NSString stringWithFormat:@"%@",[formatter stringFromDate:detea]];
    NSUInteger nowHours = [curDate integerValue];
    
    NSMutableArray *hours = [NSMutableArray array];
    for (long i = 0; i <= ((appointmentEnd-(24-nowHours))%24); i++) {
        [hours addObject:hoursArray[i]];
    }
    return [NSArray arrayWithArray:hours];
}



//返回下一个小时的分钟
+ (NSArray *)getNextHoursMinures
{
    NSDate *dates = [NSDate date];
    NSTimeInterval interval = 120;//加60秒,两个小时之后的时间
    NSDate *detea = [NSDate dateWithTimeInterval:interval sinceDate:dates];
    NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"mm"];
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"BeiJing"];
    [formatter setTimeZone:timeZone];
    
    NSString *curDate = [NSString stringWithFormat:@"%@",[formatter stringFromDate:detea]];
    NSUInteger nowHours = [curDate integerValue];
    
    NSArray *minArray = @[@"00",@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34",@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45",@"46",@"47",@"48",@"49",@"50",@"51",@"52",@"53",@"54",@"55",@"56",@"57",@"58",@"59"];
    NSMutableArray *tempArray = [NSMutableArray array];
    
    for (NSInteger min=nowHours; min<60; min++) {
        
        [tempArray addObject:minArray[min]];
    }
    
    return tempArray.copy;
}
//返回60
+ (NSArray *)getNormalHoursMinures
{
       NSArray *minArray = @[@"00",@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34",@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45",@"46",@"47",@"48",@"49",@"50",@"51",@"52",@"53",@"54",@"55",@"56",@"57",@"58",@"59"];
    return minArray;
}
//返回最后一个小时的分钟
+ (NSArray *)getLastHoursMinures
{
    NSDate *dates = [NSDate date];
    NSTimeInterval interval = 0 ;
    NSDate *detea = [NSDate dateWithTimeInterval:interval sinceDate:dates];
    NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"mm"];
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"BeiJing"];
    [formatter setTimeZone:timeZone];
    
    NSString *curDate = [NSString stringWithFormat:@"%@",[formatter stringFromDate:detea]];
    NSUInteger nowHours = [curDate integerValue];
    
    NSArray *minArray = @[@"00",@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34",@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45",@"46",@"47",@"48",@"49",@"50",@"51",@"52",@"53",@"54",@"55",@"56",@"57",@"58",@"59"];
    
    NSMutableArray *tempArray = [NSMutableArray array];
    
    for (NSInteger min=0; min<nowHours; min++) {
        
        [tempArray addObject:minArray[min]];
    }
    return tempArray.copy;
}

+ (NSArray *)getRentMinutes
{
     NSArray *minArray = @[@"00",@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34",@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45",@"46",@"47",@"48",@"49",@"50",@"51",@"52",@"53",@"54",@"55",@"56",@"57",@"58",@"59"];
    
    return minArray;
}

+ (NSArray *)getLastHoursMinutes
{
    NSDate *dates = [NSDate date];
    NSTimeInterval interval = 0 ;
    NSDate *detea = [NSDate dateWithTimeInterval:interval sinceDate:dates];
    NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"mm"];
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"BeiJing"];
    [formatter setTimeZone:timeZone];
    
    NSString *curDate = [NSString stringWithFormat:@"%@",[formatter stringFromDate:detea]];
    NSUInteger nowHours = [curDate integerValue];
    
    NSArray *minArray = @[@"00",@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34",@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45",@"46",@"47",@"48",@"49",@"50",@"51",@"52",@"53",@"54",@"55",@"56",@"57",@"58",@"59"];
    
    NSMutableArray *tempArray = [NSMutableArray array];
    
    for (NSInteger min=0; min<nowHours; min++) {
        
        [tempArray addObject:minArray[min]];
    }
    return tempArray.copy;
}

+ (NSArray *)getTodayRentMinutes
{
    NSDate *dates = [NSDate date];
    NSTimeInterval interval = 0 ;
    NSDate *detea = [NSDate dateWithTimeInterval:interval sinceDate:dates];
    NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"mm"];
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"BeiJing"];
    [formatter setTimeZone:timeZone];
    
//    NSDate *date = [NSDate date];
    NSString *curDate = [NSString stringWithFormat:@"%@",[formatter stringFromDate:detea]];
    NSUInteger nowHours = [curDate integerValue];
    if(nowHours<10){
        return @[@"00",@"10",@"20",@"30",@"40",@"50"];
    }else if (nowHours<20){
        return @[@"10",@"20",@"30",@"40",@"50"];
    }else if (nowHours<30){
        return @[@"20",@"30",@"40",@"50"];
    }else if (nowHours<40){
        return @[@"30",@"40",@"50"];
    }else if(nowHours<50){
        return @[@"40",@"50"];
    }else if(nowHours<60){
        return @[@"50"];
    }else{
        return nil;
    }
}

+ (NSString *)getLaterDateWithDays:(NSUInteger)day
{
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    
    NSDateComponents *comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:[NSDate date]];
    
    NSDateComponents *adcomps = [[NSDateComponents alloc] init];
    
    [adcomps setYear:0];
    
    [adcomps setMonth:0];
    
    [adcomps setDay:+day];
    
    
    NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:[NSDate date] options:0];
    
    NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];

            NSString *curDate=[NSString stringWithFormat:@"%@",[formatter stringFromDate:newdate]];
    return curDate;

}



@end
